package com.scorpio.complain.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.scorpio.common.annotation.DataSource;
import com.scorpio.common.constant.Constants;
import com.scorpio.common.enums.DataSourceType;
import com.scorpio.common.service.impl.BaseServiceImpl;
import com.scorpio.common.utils.StringUtils;
import com.scorpio.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.scorpio.complain.mapper.BizReportMapper;
import com.scorpio.complain.domain.BizReportEntity;
import com.scorpio.complain.service.IBizReportService;

/**
 * 匿名投诉Service业务层处理
 *
 * @author scorpio
 * @date 2020-10-16
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class BizReportServiceImpl extends BaseServiceImpl<BizReportMapper, BizReportEntity> implements IBizReportService {

    @Autowired
    private ISysConfigService sysConfigService;

    /**
     * 查询匿名投诉
     *
     * @param id 匿名投诉ID
     * @return 匿名投诉
     */
    @Override
    public BizReportEntity selectById(Long id) {
        return baseDao.selectById(id);
    }

    /**
     * 查询匿名投诉列表
     *
     * @param entity 匿名投诉
     * @return 匿名投诉
     */
    @Override
    public List<BizReportEntity> selectList(BizReportEntity entity) {
        List<BizReportEntity> list = baseDao.list(entity);
        String jures_host = sysConfigService.selectConfigByKey(Constants.APP_JURES_HOST);
        for (BizReportEntity item : list) {
            List<String> images = new ArrayList<>();
            if (!StringUtils.isEmpty(item.getExplainImg())) {
                String[] array = item.getExplainImg().split(",");
                for (String image : array) {
                    if (StringUtils.isEmpty(image)) continue;
                    images.add(jures_host + image);
                }
            }
            item.setImages(images);
        }
        return list;
    }

    /**
     * 新增匿名投诉
     *
     * @param entity 匿名投诉
     * @return 结果
     */
    @Override
    public int save(BizReportEntity entity) {
        return baseDao.insert(entity);
    }

    /**
     * 修改匿名投诉
     *
     * @param entity 匿名投诉
     * @return 结果
     */
    @Override
    public int update(BizReportEntity entity) {
        return baseDao.updateById(entity);
    }

    /**
     * 批量删除匿名投诉
     *
     * @param ids 需要删除的匿名投诉ID
     * @return 结果
     */
    @Override
    public int deleteByIds(Long[] ids) {
        return baseDao.updateDeleteBatchIds(Arrays.asList(ids));
    }

}
